#!/bin/bash

###########################################
#安装 console-7.2
###########################################


#安装 PHP 8.2 
##################################################################################
#安装基础依赖
yum install -y gcc make bzip2-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel libxslt-devel openssl-devel gd-devel
#安装oniguruma库
yum install -y oniguruma oniguruma-devel
#下载并解压 PHP 8.2 源代码
cd /home
wget https://www.php.net/distributions/php-8.2.10.tar.gz
tar -zxvf php-8.2.10.tar.gz
cd php-8.2.10
#配置编译选项
./configure --enable-mbstring --with-curl --with-openssl --with-zlib --with-mysqli --with-pdo-mysql --with-external-gd --with-jpeg --with-freetype
#编译安装
make -j
make install
#配置 PHP
cp php.ini-production /usr/local/lib/php.ini
#查看版本信息
php -v


#安装 Composer
##################################################################################
#1、下载Composer安装脚本
cd /home
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
#2、验证安装脚本的哈希值
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
#3、安装Composer到 /usr/local/bin 目录，并且把可执行文件命名为 composer
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
#4、查看Composer版本信息
composer --version

#安装console
##################################################################################
#下载源码，并切换到源码目录
git clone https://github.com/symfony/console.git
cd console
git checkout 7.2
#安装依赖包
composer install



#验证安装
##################################################################################
#编写测试脚本test.php
#执行测试脚本
php test.php hello:world
#如果能正确输出Hello, World!，则表明 Symfony Console 组件在本地编译安装成功。
#测试脚本test.php

<?php
require __DIR__. '/vendor/autoload.php';

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class HelloWorldCommand extends Command
{
    protected function configure()
    {
        $this->setName('hello:world')->setDescription('Say hello world');
    }

    // 明确声明返回类型为 int
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln('Hello, World!');
        return Command::SUCCESS;
    }
}

$application = new Application();
$application->add(new HelloWorldCommand());
$application->run();



